package count.negative.devau;

import android.graphics.Bitmap;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import count.negative.devau.service.ProgramService;

/**
 * @author count.negative
 * 
 */
public class TvWebViewClient extends WebViewClient {

	private ProgramService ps;

	public TvWebViewClient(ProgramService ps) {
		this.ps = ps;
	}

	/* (non-Javadoc)
	 * @see android.webkit.WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String)
	 */
	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		view.loadDataWithBaseURL(ps.getBaseURL(), ps.receiveHTML(url), "text/html"/*; charset=UTF-8"*/, "UTF-8", ps.getBaseURL());
		return true;//super.shouldOverrideUrlLoading(view, url);
	}

	/* (non-Javadoc)
	 * @see android.webkit.WebViewClient#onPageStarted(android.webkit.WebView, java.lang.String, android.graphics.Bitmap)
	 */
	@Override
	public void onPageStarted(WebView view, String url, Bitmap favicon) {
		Log.d("PS", "onPageStarted " + view);
		super.onPageStarted(view, url, favicon);
	}

	/* (non-Javadoc)
	 * @see android.webkit.WebViewClient#onPageFinished(android.webkit.WebView, java.lang.String)
	 */
	@Override
	public void onPageFinished(WebView view, String url) {
		Log.d("PS", "onPageFinished");
		super.onPageFinished(view, url);
	}

	/* (non-Javadoc)
	 * @see android.webkit.WebViewClient#onReceivedError(android.webkit.WebView, int, java.lang.String, java.lang.String)
	 */
	@Override
	public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
		Log.d("PS", "onReceivedError");
		super.onReceivedError(view, errorCode, description, failingUrl);
	}
}
